package com.hliu.shiro.service.impl;

import com.hliu.core.dao.IBaseHibernateDao;
import com.hliu.core.service.impl.BaseHibernateService;
import com.hliu.shiro.dao.IUserDao;
import com.hliu.shiro.dao.impl.UserDao;
import com.hliu.shiro.model.User;
import com.hliu.shiro.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * author: 6
 * date: 13-4-18
 */
@Service("userService")
public class UserService extends BaseHibernateService<User, Long> implements IUserService {

	private IUserDao iUserDao;

	@Override
	@Autowired
	@Qualifier("userDao")
	public void setiBaseDao(IBaseHibernateDao<User, Long> iBaseDao) {
		super.iBaseDao = iBaseDao;
		this.iUserDao = (UserDao) iBaseDao;
	}

	@Override
	public boolean getExistUserByPrincipalAndCredentials(String username, String password) {
		Long count = iUserDao.getPrincipalAndCredentials(username, password);
		if (count > 0) {
			return true;
		}
		return false;
	}

	@Override
	public User getUserAllRolsAndPermission(String username) {
		return iUserDao.getUserAllRolsAndPermission(username);
	}

	@Override
	public boolean getExistUserByUserName(String username) {
		Long count = iUserDao.getUserCountByUserName(username);
		if (count > 0) {
			return true;
		}
		return false;
	}

	@Override
	public User getUserByUserName(String username) {
		return iUserDao.getUserByUserName(username);
	}
}
